package com.yxx.validator;

import cn.hutool.core.util.ObjectUtil;
import com.yxx.entityModel.vo.request.CommentRequest;
import com.yxx.validator.groups.ArticleTalk;
import com.yxx.validator.groups.Link;
import com.yxx.validator.groups.ParentIdNotNull;
import com.yxx.validator.groups.ParentIdNull;
import org.hibernate.validator.spi.group.DefaultGroupSequenceProvider;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import static com.yxx.enums.CommentTypeEnum.*;

/**
 * 评论分组校验器
 * @author yuxiangxun
 * @date 2025/2/10
 * @apiNote
 */
public class CommentProvider implements DefaultGroupSequenceProvider<CommentRequest> {
    @Override
    public List<Class<?>> getValidationGroups(CommentRequest commentRequest) {
        List<Class<?>> defaultGroupSequence = new ArrayList<>();
        defaultGroupSequence.add(CommentRequest.class);
        if(ObjectUtil.isNotNull(commentRequest)){
            if(commentRequest.getCommentType().equals(ARTICLE.getType()) || commentRequest.getCommentType().equals(TALK.getType())){
                defaultGroupSequence.add(ArticleTalk.class);
            }
            if(commentRequest.getCommentType().equals(LINK.getType())){
                defaultGroupSequence.add(Link.class);
            }
            if(Objects.isNull(commentRequest.getParentId())){
                defaultGroupSequence.add(ParentIdNull.class);
            }
            if(Objects.nonNull(commentRequest.getParentId())){
                defaultGroupSequence.add(ParentIdNotNull.class);
            }
        }
        return defaultGroupSequence;
    }
}
